<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Break</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>Break</h1>

<p>Exits (terminates) a <a href="Loop.htm">loop</a>. Valid inside any kind of <a href="Loop.htm">loop</a>.</p>

<pre class="Syntax">Break [, LoopLabel]</pre>
<p><span class="ver">[AHK_L 59+]:</span> If specified, <em>LoopLabel</em> identifies which loop this statement should apply to; either by <a href="../misc/Labels.htm">label name</a> or numeric nesting level. If omitted or 1, this statement applies to the innermost loop in which it is enclosed. <em>LoopLabel</em> must be a constant value - variables and expressions are not supported. If a <a href="../misc/Labels.htm">label</a> is specified, it must point directly at a loop command.</p>
<p>The use of Break and <a href="Continue.htm">Continue</a> are encouraged over <a href="Goto.htm">goto</a> since they usually make scripts more readable and maintainable.</p>
<h3>Related</h3>
<p><a href="Continue.htm">Continue</a>, <a href="Loop.htm">Loop</a>, <a href="While.htm">While-loop</a>, <a href="For.htm">For-loop</a>, <a href="Block.htm">Blocks</a>, <a href="../misc/Labels.htm">Labels</a></p>
<h3>Example</h3>
<pre class="NoIndent">Loop
{
    ...
    if var &gt; 25
        break
    ...
    if var &lt;= 5
        continue
}</pre>
<pre class="NoIndent"><em>; Break the outer loop from within a nested loop.</em>
<b>outer:</b>
Loop 3
{
    x := A_Index
    Loop 3
    {
        if (x*A_Index = 6)
            <b>break outer</b>  <em>; Equivalent to <b>break 2</b> or <b>goto break_outer</b>.</em>
        MsgBox %x%,%A_Index%
    }
}
break_outer: <em>; For goto.</em>
</pre>

</body>
</html>
